<%@page import="isquirrel.servlets.handler.HttpDBServlet"%>
<%@page import="isquirrel.util.Utilities"%>
<%@page import="isquirrel.util.HibernateUtil"%>
<%@page import="java.util.ArrayList"%>

<%

if (request.getAttribute("noview") != null){
	return;
}

ArrayList<String> unrestrictedAccess = new ArrayList<String>();
unrestrictedAccess.add("login.jsp");
unrestrictedAccess.add("register.jsp");
unrestrictedAccess.add("memory.jsp");

ArrayList<String> memberLayout = new ArrayList<String>();
memberLayout.add("home.jsp");
memberLayout.add("friends.jsp");
memberLayout.add("network.jsp");
memberLayout.add("profile.jsp");


String layout = "";

if (!unrestrictedAccess.contains(request.getParameter("p"))) {
	if (!HttpDBServlet.isUserLoggedIn(request)) {
		//redirect to login page
		request.setAttribute("p","login.jsp");
		layout = "layouts/defaultlayout.jsp";
	}
}

//choose layout
if (layout.equals("")) {
	layout = "layouts/defaultlayout.jsp";
	if (memberLayout.contains(request.getParameter("p"))) {
			layout = "layouts/memberlayout.jsp";
	} else if (request.getParameter("p").equals("login.jsp") && HttpDBServlet.isUserLoggedIn(request)) {
		response.sendRedirect("home");
	}
}
%>
<jsp:include page='<%= layout %>' />
